import pyautogui
import keyboard
import time

# 设置第一个屏幕点击位置（全局坐标）
TARGET_X = 1920 / 2
TARGET_Y = 1080 / 2

# 设置快捷键
# HOTKEY = ['ctrl', 'alt', 'c']
HOTKEY = ['alt', 'q']

def click_first_screen():
    # 等待 HOTKEY 所有键松开
    while any(keyboard.is_pressed(k) for k in HOTKEY):
        time.sleep(0.01)  # 防止 CPU 占用过高

    # 保存当前位置
    orig_x, orig_y = pyautogui.position()

    # 移动到目标坐标点击
    pyautogui.moveTo(TARGET_X, TARGET_Y)
    time.sleep(0.1)
    pyautogui.click()
    # 恢复鼠标位置
    pyautogui.moveTo(orig_x, orig_y)

    # 按下 Alt+Tab 切换窗口
    time.sleep(0.1)
    pyautogui.hotkey("alt", "tab")

# 注册按下任意 HOTKEY 时触发，但实际点击在松开后
keyboard.add_hotkey('+'.join(HOTKEY), click_first_screen)

print(f"快捷键 {'+'.join(HOTKEY)} 已注册，松开后执行点击。按 f11 退出。")
keyboard.wait('f11')
